style: Make padding a shorthand
authorBenjamin Otte <otte@redhat.com>
Sun, 22 May 2011 03:42:17 +0000 (05:42 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 22 May 2011 03:56:12 +0000 (05:56 +0200)
... and add the real properties:
- padding-top
- padding-left
- padding-bottom
- padding-right

gtk/gtkcssprovider.c
gtk/gtkstylecontext.c
gtk/gtkstyleproperty.c

index 37091b2685ef3687a6dea302774ba90777d38902..42f48ab7a79f4d00face368ea16dc087a44d954f 100644 (file)
  *         </entry>
  *       </row>
  *       <row>
+ *         <entry>padding-top</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>padding-top: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>padding-left</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>padding-left: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>padding-bottom</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>padding-bottom: 5;</entry>
+ *       </row>
+ *       <row>
+ *         <entry>padding-right</entry>
+ *         <entry>integer</entry>
+ *         <entry>#gint</entry>
+ *         <entry>padding-right: 5;</entry>
+ *       </row>
+ *       <row>
  *         <entry>padding</entry>
  *       </row>
  *       <row>
index 134a0f27c01b39b928384096eda176cb7b54538a..7f6ebff8ed2e3903342d5179cf9724f539f16ea9 100644 (file)
@@ -3515,28 +3515,27 @@ gtk_style_context_get_padding (GtkStyleContext *context,
 {
   GtkStyleContextPrivate *priv;
   StyleData *data;
-  const GValue *value;
-  GtkBorder *b;
+  int top, left, bottom, right;
 
   g_return_if_fail (padding != NULL);
-  *padding = fallback_border;
-
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
   priv = context->priv;
   g_return_if_fail (priv->widget_path != NULL);
 
   data = style_data_lookup (context);
-  value = _gtk_style_properties_peek_property (data->store,
-                                               "padding",
-                                               state,
-                                               NULL);
+  gtk_style_properties_get (data->store,
+                            state,
+                            "padding-top", &top,
+                            "padding-left", &left,
+                            "padding-bottom", &bottom,
+                            "padding-right", &right,
+                            NULL);
 
-  if (value)
-    {
-      b = g_value_get_boxed (value);
-      *padding = *b;
-    }
+  padding->top = top;
+  padding->left = left;
+  padding->bottom = bottom;
+  padding->right = right;
 }
 
 /**
index 8925ba46cebdbc2516ad461d7269584901b4def1..9f58bd5cb08990a8c80eeccd39fa4d3b8e182061 100644 (file)
@@ -1237,6 +1237,25 @@ pack_border_width (GValue             *value,
                "border-bottom-width", "border-right-width");
 }
 
+static GParameter *
+unpack_padding (const GValue *value,
+                guint        *n_params)
+{
+  return unpack_border (value, n_params,
+                        "padding-top", "padding-left",
+                        "padding-bottom", "padding-right");
+}
+
+static void
+pack_padding (GValue             *value,
+              GtkStyleProperties *props,
+              GtkStateFlags       state)
+{
+  pack_border (value, props, state,
+               "padding-top", "padding-left",
+               "padding-bottom", "padding-right");
+}
+
 /*** API ***/
 
 static void
@@ -1440,10 +1459,32 @@ gtk_style_property_init (void)
                                                               "Margin",
                                                               GTK_TYPE_BORDER, 0));
   gtk_style_properties_register_property (NULL,
-                                          g_param_spec_boxed ("padding",
+                                          g_param_spec_int ("padding-top",
+                                                            "padding top",
+                                                            "Padding at top",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("padding-left",
+                                                            "padding left",
+                                                            "Padding at left",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("padding-bottom",
+                                                            "padding bottom",
+                                                            "Padding at bottom",
+                                                            0, G_MAXINT, 0, 0));
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_int ("padding-right",
+                                                            "padding right",
+                                                            "Padding at right",
+                                                            0, G_MAXINT, 0, 0));
+  _gtk_style_property_register           (g_param_spec_boxed ("padding",
                                                               "Padding",
                                                               "Padding",
-                                                              GTK_TYPE_BORDER, 0));
+                                                              GTK_TYPE_BORDER, 0),
+                                          NULL,
+                                          unpack_padding,
+                                          pack_padding);
   gtk_style_properties_register_property (NULL,
                                           g_param_spec_int ("border-top-width",
                                                             "border top width",